<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
 .upload-div{
	margin-top: 10px
 }
.reselect {
    font-size: 12px;
    border-radius: 10px;
    vertical-align: bottom;
	padding: 2px 12px;
    margin-top: 10px;
}
#other-format {
	font-size: 16px;
	margin-bottom: 8px;
}
#video {
    max-height: 500px;
}
#grade-form img {
    max-height: 400px;
}
</style>
<div class="page-header">
    <h1>
        <?php if(isset($gradeInfo['id']) && $gradeInfo['id']): ?>编辑<?php else: ?>新增<?php endif ?>年级
    </h1>
</div>
<div class="col-xs-12">
    <form id="grade-form" class="form-horizontal">
        <input type="hidden" name="id" value="<?= isset($gradeInfo) ? $gradeInfo['id'] : '' ?>" />
        <input type="hidden" name="default_grade_id" value="<?= isset($gradeInfo['default_grade_id']) ? $gradeInfo['default_grade_id'] : '' ?>" />
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">所属校区：</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" disabled="" value="<?=$campusInfo['campus_name']?>" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">所属年级：</label>
            <div class="col-sm-6">
                <span class="block input-icon input-icon-right pd0">
                    <input class="width-100" type="text" placeholder="请选择所属年级" id="select-grade-grade" value="<?= isset($gradeInfo['default_grade_name']) ? $gradeInfo['default_grade_name'] : '' ?>" />
                    <i class="ace-icon fa fa-graduation-cap"></i>
                </span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">年级别名：</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" name="grade_name" value="<?= isset($gradeInfo['grade_name']) ? $gradeInfo['grade_name'] : '' ?>" placeholder="请填写年级别名"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">排序（数值越大越靠前）：</label>
            <div class="col-sm-6">
                <input class="form-control" type="number" name="sort_level" value="<?= isset($gradeInfo['sort_level']) ? $gradeInfo['sort_level'] : 0 ?>" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">入学年份：</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" id="year-picker" name="year_of_admission" value="<?= isset($gradeInfo['year_of_admission']) ? $gradeInfo['year_of_admission'] : '' ?>" placeholder="请选择入学年份"/>
            </div>
        </div>
        <!-- <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right">升级日期：</label>
            <div class="col-sm-6">
                <input class="form-control" type="text" id="date-picker" name="auto_upgrade_date" value="<?= isset($gradeInfo['auto_upgrade_date']) ? $gradeInfo['auto_upgrade_date'] : '' ?>" placeholder="请选择升级日期"/>
            </div>
        </div> -->
        <div class="clearfix">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="submit">
                    <i class="ace-icon fa fa-check"></i> 提交
                </button>
            </div>
        </div>
	</form>
</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
$(function() {
    // 初始化选择资源年级控件
    $("#select-grade-grade").selectSourceGrade({
        "modalDataUrl": '<?= admin_url('school/select_default_grade_plugin_data_source') ?>',
        "resultDom": $("[name=default_grade_id]"),
	});
    var myDate = new Date();
    var tYear = myDate.getFullYear();
    $('#year-picker').datetimepicker({
        format: 'YYYY',
        // maxDate: '"' + tYear + '"'
    });
    $('#date-picker').datetimepicker({
        format: 'YYYY-MM-DD'
    });
	// 提交表单
	var form = $("#grade-form");
	var submitUrl = "<?=admin_url('classes/save_grade_action')?>";
	form_submit(form, submitUrl, function(res) {
		tips_alert(res.msg, res.success, function(){
			if(res.success) {
				window.location.href = "<?=admin_url('classes/grade')?>";
            } else {
                if(res.msg == '下一年级的年级别名未填写，不予升级') {
                    // 清空升级日期
                    $("[name=auto_upgrade_date]").val('');
                }
            }
		});
	})
})
</script>